package com.sensePlusVR.net;

import org.apache.http.Header;
import org.apache.http.entity.ByteArrayEntity;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.EditText;

import com.alibaba.fastjson.JSON;
import com.sensePlusVR.activity.listener.CPUInfoListener;
import com.sensePlusVR.activity.mine.CoreSettingActivity;
import com.sensePlusVR.activity.user.LoginActivity;
import com.sensePlusVR.activity.user.RegisterVerifyEmailActivity;
import com.sensePlusVR.application.VRApplication;
import com.sensePlusVR.bean.AppStatisticsDto;
import com.sensePlusVR.bean.AuthorizeReqDto;
import com.sensePlusVR.bean.ChangePasswordReqDto;
import com.sensePlusVR.bean.CpuInfo;
import com.sensePlusVR.bean.FeedbackItem;
import com.sensePlusVR.bean.ForgotPasswordDto;
import com.sensePlusVR.bean.LoginResultDto;
import com.sensePlusVR.bean.RegisterReqDto;
import com.sensePlusVR.bean.ServerErrorMsg;
import com.sensePlusVR.bean.UserDto;
import com.sensePlusVR.main.MainActivity;
import com.sensePlusVR.main.R;
import com.sensePlusVR.manager.DataCenter;
import com.sensePlusVR.utils.AESSecurityUtil;
import com.sensePlusVR.utils.AndroidDeviceUtil;
import com.sensePlusVR.utils.AppManager;
import com.sensePlusVR.utils.Constant;
import com.sensePlusVR.utils.ConstantURL;
import com.sensePlusVR.utils.DeviceType;
import com.sensePlusVR.utils.DialogUtils;
import com.sensePlusVR.utils.MyLog;
import com.sensePlusVR.utils.MyPageJump;
import com.sensePlusVR.utils.MySharedPreferences;
import com.sensePlusVR.utils.MyToast;
import com.sensePlusVR.utils.NetworkUtils;
import com.sensePlusVR.utils.StringUtils;
import com.sensePlusVR.utils.UserUtil;
import com.umeng.analytics.MobclickAgent;
/**
 * 
 * @author: Loren
 * @create: 2016-8-10下午3:05:32
 * @desc: 网络请求聚集
 *
 */
@SuppressWarnings({"unused","deprecation"})
public class NetRequestManager{
	private static final String TAG = NetRequestManager.class.getSimpleName();
	/**
	 * 登录
	 * @param mContext
	 * @param userNameIn
	 * @param passwordIn
	 */
	private static ProgressDialog dialogLogin;
	private static int countLogin = 0; 
	private static Integer locked = 0;
    public static void startLoginRequestResult(final Context mContext,
            final String userNameIn, final String passwordIn) {
        if (!NetworkUtils.isNetworkAvailable(mContext)) {
            MyToast.showMessage(mContext, R.string.link_network_failure);
            return;
        }
        
        if(dialogLogin == null){
        	dialogLogin =  new ProgressDialog(mContext);
        	 dialogLogin.setCancelable(false);
             dialogLogin.setMessage(mContext.getString(R.string.tt_dialog_login));
             dialogLogin.show();
        }
        
        //登录的用户名为标准邮箱则存储，方便忘记密码及登录免输入，然后成功后再存储最新的用户名
        boolean loginIsEmail = StringUtils.isEmail(userNameIn);
        MyLog.d(TAG, "loginIsEmail : " + loginIsEmail);
        if(loginIsEmail){
        	  MySharedPreferences.save2(mContext,MySharedPreferences.NAME_NOT_CLEAR, Constant.LOGIN_SUCCESS_LOGINNAME,
        			  userNameIn);
        }
        
        AuthorizeReqDto reqDto = new AuthorizeReqDto();
        reqDto.setLoginName(userNameIn);
        try {
        	char[] encrypte = AESSecurityUtil.encrypt(passwordIn, Constant.KEY_AES);
        	System.out.println(encrypte);
        	reqDto.setPassword(encrypte);
		} catch (Exception e) {
			e.printStackTrace();
		}
        String json = JSON.toJSONString(reqDto);
        MyLog.d(TAG, "startLoginRequestResult json in : " + json);
        MyLog.d(TAG, "loginURL : " + ConstantURL.LOGIN_URL);
        final String url = ConstantURL.LOGIN_URL;
        RequestUtils.clientPost(mContext, url, new ByteArrayEntity(json.getBytes()), Constant.STR_APPLICATION_JSON,new NetCallBack(){
        	
 			@Override
			public void onMySuccess(int statusCode, Header[] aheader,
					JSONObject jsonobject) {
				super.onMySuccess(statusCode, aheader, jsonobject);
				if(jsonobject == null){
					MyLog.e(TAG, "startLoginRequestResult onMySuccess jsonobject == null");
					return;
				}
				Log.d(TAG, "startLoginRequestResult onMySuccess jsonobject : " + jsonobject.toString());
				LoginResultDto loginResultDto = JSON.parseObject(
						jsonobject.toString(), LoginResultDto.class);
                if (loginResultDto != null) {
                	 locked = loginResultDto.getLocked();
                           MySharedPreferences.save2(mContext,MySharedPreferences.NAME_NOT_CLEAR,
                                   Constant.IS_FIRST_INSTANT, true);
                           MySharedPreferences.save2(mContext, MySharedPreferences.NAME_NOT_CLEAR, 
                        		   Constant.LOGIN_SUCCESS_LOCKED, locked);
                           // 保存
                           MySharedPreferences.save2(mContext,MySharedPreferences.NAME_NOT_CLEAR,
                                   Constant.LOGIN_SUCCESS_TOKEN,
                                   loginResultDto.getToken());
                               MyLog.d(TAG, " login Token : " + loginResultDto.getToken());
                }
               startGetAccountInfo(mContext);
               //主要为了拉取actor信息（因为GameUpgradeUtil中如果没有token则拉取失败，下次拉取只能在FollowFragment中拉取，为了数据及时，在此处处理）
               DataCenter dc = DataCenter.getInstans();
               dc.getActors(true);
			}
			
			@Override
			public void onMyFailure(int statusCode, Header[] headers,
					Throwable throwable, JSONObject errorResponse) {
				super.onMyFailure(statusCode, headers, throwable, errorResponse);
				if(throwable != null){
					MyLog.d(TAG, "throwable : " + throwable.getMessage());
				}
				
				if(statusCode == 0){
					if(countLogin < 3){
						countLogin++;
						MyLog.d(TAG, "startLoginRequestResult try count : " + countLogin);
						startLoginRequestResult(mContext, userNameIn, passwordIn);
						return;
					}else{
						countLogin = 0;
					}
				}
				  if (dialogLogin != null && dialogLogin.isShowing()) {
					  
					  dialogLogin.dismiss();
					  
					  dialogLogin = null;
					  
	                }
				  
				 isCommonErr(statusCode, errorResponse, mContext,url);
			}
        });
    }
    
    /**
     * 获取账户信息并保存
     * 
     */
    public static void startGetAccountInfo(final Context mContext) {
        if (!NetworkUtils.isNetworkAvailable(mContext)) {
            MyToast.showMessage(mContext, R.string.link_network_failure);
            return;
        }
        
        String token = MySharedPreferences.getString2(VRApplication.getAppContext(), MySharedPreferences.NAME_NOT_CLEAR,Constant.LOGIN_SUCCESS_TOKEN);
		MyLog.d(TAG, "token startGetAccountInfo : " + token);
		RequestUtils.clientToken.addHeader(Constant.STR_X_AUTH_TOKEN,token);
		final String url = ConstantURL.ACCOUNT_URL;
	    RequestUtils.clientTokenGet(mContext,url, new NetCallBack() {
				
				@Override
				public void onMySuccess(int statusCode, Header[] aheader,
						JSONObject jsonobject) {
					super.onMySuccess(statusCode, aheader, jsonobject);
					MyLog.d(TAG, "startGetAccountInfo onMySuccess statusCode : " + statusCode);
					if(jsonobject == null){
						MyLog.e(TAG, "startGetAccountInfo onMySuccess jsonobject == null");
						return;
					}
					Log.d(TAG, "startGetAccountInfo onMySuccess jsonobject : " + jsonobject.toString());
					if(statusCode == Constant.HTTP_200){
						 UserDto userDto = JSON.parseObject(jsonobject.toString(),
		                         UserDto.class);
						//Umeng账号统计登入
						MobclickAgent.onProfileSignIn(String.valueOf(userDto.getId()));
						MyLog.d(TAG,"startGetAccountInfo userDto : " + userDto.toString());

						 MyLog.d(TAG, "Successful login");
		                 // 保存用户信息
		                 UserUtil.saveUserInfo(mContext, userDto, false);
		                 if (dialogLogin != null) {
		                	 dialogLogin.dismiss();
		                	 dialogLogin = null;
		                 }
							MyPageJump.pageJump(mContext, MainActivity.class);
							AppManager.getInstance().finishActivity(
									(Activity) mContext);
					}
				}
				
				@Override
				public void onMyFailure(int statusCode, Header[] headers,
						Throwable throwable, JSONObject errorResponse) {
					super.onMyFailure(statusCode, headers, throwable, errorResponse);
					  if (dialogLogin != null) {
						  dialogLogin.dismiss();
						  dialogLogin = null;
	                     }
					 boolean isSameUser = MySharedPreferences.getBoolean2(mContext,MySharedPreferences.NAME_NOT_CLEAR,
	                         Constant.IS_SAME_USER);
	                 if (!isSameUser) {  
		                 UserDto userDto = new UserDto();
		                 UserUtil.saveUserInfo(mContext, userDto, false);
		                 }
	              isCommonErr(statusCode,errorResponse, mContext,url);
				}
			});
    }
    
    /**
     * 注册
     * @param mContext
     * @param loginName
     * @param password
     */
    private static ProgressDialog dialogRegister; 
    private static int countRegister = 0;
    //"android"
    public static void startRegisterRequestResult(final Context mContext,final String loginName,final String password) {
        if (!NetworkUtils.isNetworkAvailable(mContext)) {
            MyToast.showMessage(mContext, R.string.link_network_failure);
            return;
        }
        
        //UserUtil.saveLoginNameUser(mContext, loginName);
        if(dialogRegister==null){
        	dialogRegister = new ProgressDialog(mContext);
        	dialogRegister.setCancelable(false);
        	dialogRegister.setMessage(mContext.getString(R.string.msg_common_i_wait));
        	dialogRegister.show();
        }
        
        RegisterReqDto registerReqDto = new RegisterReqDto();
        registerReqDto.setLoginName(loginName);
        try {
        	char[] encrypte = AESSecurityUtil.encrypt(password, Constant.KEY_AES);
        	System.out.println(encrypte);
        	registerReqDto.setPassword(encrypte);
		} catch (Exception e) {
			e.printStackTrace();
		}
        registerReqDto.setEmail(loginName);
        String json = JSON.toJSONString(registerReqDto);
  
            MyLog.d(TAG,"startRequestResult register json in : " + json);
            final String url = ConstantURL.REGISTER_URL;
            MyLog.d(TAG, "startRequestResult register url : " + url);
            RequestUtils.clientPost(mContext, url, new ByteArrayEntity(json.getBytes()), Constant.STR_APPLICATION_JSON, new NetCallBack() {
				@Override
				public void onMySuccess(int statusCode, Header[] aheader,
						JSONObject jsonobject) {
					super.onMySuccess(statusCode, aheader, jsonobject);
					if(dialogRegister != null){
						dialogRegister.dismiss();
						dialogRegister = null;
					}
					MyLog.d(TAG, "startRequestResult onMySuccess statusCode : " + statusCode);
					if(jsonobject == null){
						MyLog.e(TAG, "startRequestResult onMySuccess jsonobject == null");
						return;
					}
					MyLog.d(TAG, "startRequestResult onMySuccess jsonobject : " + jsonobject);
					if(statusCode == Constant.HTTP_201){
						 // 注册成功后，数据保存在本地
		                   UserDto userDto = JSON.parseObject(jsonobject.toString(),
		                           UserDto.class);
		                   if (userDto != null) {
		                       // 注册成功
		                	   MyLog.d(TAG, "Successfully registered");
		                       UserUtil.clearnData(mContext);
		                       
		                       MySharedPreferences.save2(mContext,MySharedPreferences.NAME_NOT_CLEAR, Constant.REGISTER_TEMP_EMAIL,
		                               loginName);
		                       // 密码
		                       MySharedPreferences.save2(mContext, MySharedPreferences.NAME_NOT_CLEAR,Constant.REGISTER_TEMP_PASSWORD,
		                               password);
		                       MyPageJump.pageJump(mContext, RegisterVerifyEmailActivity.class);
		            		//AppManager.getInstance().finishActivity((Activity)mContext);
		                   }
					}
				}
				@Override
				public void onMyFailure(int statusCode, Header[] headers,
						Throwable throwable, JSONObject errorResponse) {
					super.onMyFailure(statusCode, headers, throwable, errorResponse);
				    if(statusCode == 0 || errorResponse == null){
			        	MyLog.e(TAG, "statusCode == 0 or errorResponse == null");
				    }
					if(throwable != null){
						MyLog.d(TAG, "throwable : " + JSON.toJSONString(throwable));
					}
					if(statusCode == 0){
						if(countRegister < 3){
							countRegister++;
							MyLog.d(TAG, "startRequestResult try count : " + countRegister);
							startRegisterRequestResult(mContext, loginName, password);
							return;
						}else{
							countRegister = 0;
						}
					}
					if(dialogRegister != null){
						dialogRegister.dismiss();
						dialogRegister = null;
					}
					isCommonErr(statusCode, errorResponse, mContext,url);
				}
			});
    }
    
    /**
     * 退出登录
     * @param mContext
     */
    public static void startLoginOut(final Context mContext){
//        if (!NetworkUtils.isNetworkAvailable(mContext)) {
//            //MyToast.showMessage(mContext, R.string.link_network_failure);
//            UserUtil.clearnData(mContext);
//			  AppManager.getInstance().finishAllActivity();
//			  MyPageJump.pageJump(mContext,
//						LoginActivity.class);
//            return;
//        }
//        
//        final ProgressDialog dialogStatic = new ProgressDialog(mContext);
//        dialogStatic.setMessage(mContext.getString(R.string.tt_dialog_login_out));
//        dialogStatic.setCancelable(false);
//        dialogStatic.show();
//        
//        String token = MySharedPreferences.getString2(mContext,MySharedPreferences.NAME_NOT_CLEAR, Constant.LOGIN_SUCCESS_TOKEN);
//        MyLog.d(TAG, "startLoginOut token : " + token);
//        RequestUtils.clientToken.addHeader(Constant.STR_X_AUTH_TOKEN,token);
//        
//        RequestUtils.clientTokenPost(mContext,ConstantURL.LOGIN_OUT_URL, new NetCallBack() {
//			@Override
//			public void onMySuccess(int statusCode, Header[] aheader,
//					JSONObject jsonobject) {
//				super.onMySuccess(statusCode, aheader, jsonobject);
//				if(dialogStatic != null)dialogStatic.dismiss();
//				MyLog.d(TAG, "startLoginOut onMySuccess statuscode : " + statusCode);
//				if(jsonobject == null){
//					MyLog.d(TAG, "startLoginOut onMySuccess jsonobject == null");
//					return;
//				}
//				Log.d(TAG, "startLoginOut onMySuccess jsonobject : " + jsonobject.toString());
//				if(statusCode == Constant.HTTP_200){
//					if(jsonobject != null){
//						ServerErrorMsg errorMsg = JSON.parseObject(jsonobject.toString(), ServerErrorMsg.class);
//						if(errorMsg.getError().equals(Constant.SERVER_SUCCESS_KEY_E000)){
//							MyLog.d(TAG, mContext.getResources().getString(R.string.msg_success_value_E000));
    						MyLog.d(TAG, "startLoginOut clean data");
    						//Umeng账号统计退出账号
    						MobclickAgent.onProfileSignOff();
    						//先不删除本地数据，当登录时候判断如果不是同一个账号再删除,先清除Token和userId
							//UserUtil.clearnData(mContext);
    						UserUtil.clearnUserMsg(mContext);
							  AppManager.getInstance().finishAllActivity();
							  MyPageJump.pageJump(mContext,
										LoginActivity.class);
//						}
//					}
//				}
//			}
//			
//			@Override
//			public void onMyFailure(int statusCode, Header[] headers,
//					Throwable throwable, JSONObject errorResponse) {
//				super.onMyFailure(statusCode, headers, throwable, errorResponse);
//				if(dialogStatic != null)dialogStatic.dismiss();
//				isCommonErr(statusCode, errorResponse, mContext);
//			}
//		});
    }
    
    /**
     * 重新获取用户信息,当修改用户名和修改性别后调用
     * @param mContext
     * @param userDtoIn
     */
	public static void startGetNewAccountInfo(final Context mContext,UserDto userDtoIn) {
		  if (!NetworkUtils.isNetworkAvailable(mContext)) {
	            MyToast.showMessage(mContext, R.string.link_network_failure);
	            return;
	        }
		  
		  final ProgressDialog dialogStatic = new ProgressDialog(mContext);
	        dialogStatic.setMessage(mContext.getString(R.string.msg_common_i_wait));
	        dialogStatic.setCancelable(false);
	        dialogStatic.show();
	        
		  if(userDtoIn == null){
			  MyLog.e(TAG, "startGetNewAccountInfo in userDto == null");
			  return;
		  }
		  
		  String json = JSON.toJSONString(userDtoIn);
		  
		  String token = MySharedPreferences.getString2(VRApplication.getAppContext(),MySharedPreferences.NAME_NOT_CLEAR, Constant.LOGIN_SUCCESS_TOKEN);
		  MyLog.d(TAG, "token startGetNewAccountInfo : " + token);
		  RequestUtils.clientToken.addHeader(Constant.STR_X_AUTH_TOKEN,token);
		  final String url = ConstantURL.ACCOUNT_URL;
		  RequestUtils.clientTokenPost(mContext,url, new ByteArrayEntity(json.getBytes()), Constant.STR_APPLICATION_JSON, new NetCallBack() {
			@Override
			public void onMySuccess(int statusCode, Header[] aheader,
					JSONObject jsonobject) {
				super.onMySuccess(statusCode, aheader, jsonobject);
				if(dialogStatic != null)dialogStatic.dismiss();
				Log.d(TAG, "startGetNewAccountInfo onMySuccess statusCode : " + statusCode);
				if(jsonobject == null){
					Log.e(TAG, "startGetNewAccountInfo onMySuccess jsonobject == null");
					return;
				}
				MyLog.d(TAG, "startGetNewAccountInfo onMySuccess jsonobject : " + jsonobject.toString());
				if(statusCode == Constant.HTTP_200){
					 UserDto userDto = JSON.parseObject(jsonobject.toString(),
	                         UserDto.class);
	                 // 登录成功提示
	                 /*MyToast.showMessage(mContext,
	                         R.string.msg_motify_account_success);*/
					 MyLog.d(TAG, "User information changed successfully");

	                 // 保存用户信息
	                 UserUtil.saveUserInfo(mContext, userDto, false);
	                 AppManager.getInstance().finishActivity((Activity)mContext);
	                 MyToast.showMessage(mContext, R.string.modify_success);
	                // MyPageJump.pageJumpAddObject(mContext, MainActivity.class, "LOGIN_INFO", userDto);
	                 //AppManager.getInstance().finishActivity((Activity)mContext);
				}
			}
			
			
			@Override
			public void onMyFailure(int statusCode, Header[] headers,
					Throwable throwable, JSONObject errorResponse) {
				super.onMyFailure(statusCode, headers, throwable, errorResponse);
				if(dialogStatic != null)dialogStatic.dismiss();
				 isCommonErr(statusCode,errorResponse, mContext,url);
			}
		});
	}
	
	/**
	 * 自动注册接口
	 * @param context
	 */
	public static void startAutoRegister(final Context context){
        if (!NetworkUtils.isNetworkAvailable(context)) {
            MyToast.showMessage(context, R.string.link_network_failure);
            return;
        }
        
        final ProgressDialog dialogStatic = new ProgressDialog(context);
        dialogStatic.setMessage(context.getString(R.string.msg_common_i_wait));
        dialogStatic.setCancelable(false);
        dialogStatic.show();
        
        String token = MySharedPreferences.getString2(context,MySharedPreferences.NAME_NOT_CLEAR, Constant.LOGIN_SUCCESS_TOKEN);
        String uniqueId = AndroidDeviceUtil.getCustomUniqueIdentifier(context);
    	final String loginName = uniqueId + Constant.REGISTER_AUTO_EMAIL_SUFFIX;
    	String email = loginName;
    	final String password = Constant.REGISTER_AUTO_PASSWORD;
    	
    	  RegisterReqDto registerReqDto = new RegisterReqDto();
          registerReqDto.setLoginName(loginName);
          try {
          	char[] encrypte = AESSecurityUtil.encrypt(password, Constant.KEY_AES);
          	System.out.println(encrypte);
          	registerReqDto.setPassword(encrypte);
  		} catch (Exception e) {
  			e.printStackTrace();
  		}
          registerReqDto.setEmail(email);
          String json = JSON.toJSONString(registerReqDto);
          
          MyLog.d(TAG,"startAutoRegister register json in : " + json);
          
        if(token != null && token != ""){
        	 RequestUtils.clientToken.addHeader(Constant.STR_X_AUTH_TOKEN,token);
        }
        
        final String url = ConstantURL.REGISTER_URL;
        
        RequestUtils.clientTokenPost(context, url, new ByteArrayEntity(json.getBytes()), Constant.STR_APPLICATION_JSON, new NetCallBack() {
			@Override
			public void onMySuccess(int statusCode, Header[] aheader,
					JSONObject jsonobject) {
				super.onMySuccess(statusCode, aheader, jsonobject);
				if(dialogStatic != null)dialogStatic.dismiss();
				MyLog.d(TAG, "startAutoRegister onMySuccess statusCode : " + statusCode);
				if(jsonobject == null){
					MyLog.e(TAG, "startAutoRegister onMySuccess jsonobject == null");
					return;
				}
				MyLog.d(TAG, "startAutoRegister onMySuccess jsonobject : " + jsonobject.toString());
				if(statusCode == Constant.HTTP_201){
					 // 注册成功后，数据保存在本地
	               UserDto userDto = JSON.parseObject(jsonobject.toString(),
	                       UserDto.class);
	               AppManager.getInstance().finishActivity(
	                       MainActivity.class);
	               if (userDto != null) {
	                   // 注册成功
	                   //MyToast.showMessage(context, R.string.msg_register_n_suc);
	            	   MyLog.d(TAG, "Successfully registered");
	                   UserUtil.clearnData(context);
	                   
	                   MySharedPreferences.save2(context, MySharedPreferences.NAME_NOT_CLEAR,Constant.REGISTER_TEMP_EMAIL,
                               loginName);
                       // 密码
                       MySharedPreferences.save2(context,MySharedPreferences.NAME_NOT_CLEAR, Constant.REGISTER_TEMP_PASSWORD,
                               password);
                       
	                   // 登陆并保存返回数据
	                  /* startLoginRequestResult(RegisterActivity.this,
	                           loginName, password);*/
	               	Intent intent = new Intent(context, RegisterVerifyEmailActivity.class);
	        		Bundle bundle = new Bundle();
	        		bundle.putString(Constant.INTENT_USER_NAME, loginName);
	        		bundle.putString(Constant.INTENT_USER_PWD, password);
	        		intent.putExtras(bundle);
	        		context.startActivity(intent);
	        		((Activity)context).overridePendingTransition(android.R.anim.fade_in,
	        				android.R.anim.fade_out);
	               }
				}
			}
			@Override
			public void onMyFailure(int statusCode, Header[] headers,
					Throwable throwable, JSONObject errorResponse) {
				super.onMyFailure(statusCode, headers, throwable, errorResponse);
				if(dialogStatic != null)dialogStatic.dismiss();
				isCommonErr(statusCode, errorResponse,context,url);
			}
		});
	}
	
	/**
	 * 上传用户统计信息
	 * @param context
	 * @param startTime
	 * @param endTime
	 */
	public static void startUploadAppStatistics(final Context context,String startTime,String endTime){
		  if (!NetworkUtils.isNetworkAvailable(context)) {
	            MyToast.showMessage(context.getApplicationContext(), R.string.link_network_failure);
	            return;
	        }
		  
		  final ProgressDialog dialogStatic = new ProgressDialog(context);
		  	dialogStatic.setMessage(context.getString(R.string.msg_common_i_wait));
	        dialogStatic.setCancelable(false);
	        dialogStatic.show();
	        
		  AppStatisticsDto appStatisticsDto = new AppStatisticsDto(startTime, endTime);
		  String json = JSON.toJSONString(appStatisticsDto);
		  
		  String token = MySharedPreferences.getString2(VRApplication.getAppContext(),MySharedPreferences.NAME_NOT_CLEAR, Constant.LOGIN_SUCCESS_TOKEN);
		  MyLog.d(TAG, "token startUploadAppStatistics : " + token);
		  RequestUtils.clientToken.addHeader(Constant.STR_X_AUTH_TOKEN,token);
		  final String url = ConstantURL.APP_UPLOAD_STATISTICS;
		  RequestUtils.clientTokenPost(context, url, new ByteArrayEntity(json.getBytes()), Constant.STR_APPLICATION_JSON, new NetCallBack() {
			
			@Override
			public void onMySuccess(int statusCode, Header[] aheader,
					JSONObject jsonobject) {
				super.onMySuccess(statusCode, aheader, jsonobject);
				if(dialogStatic != null)dialogStatic.dismiss();
				MyLog.d(TAG, "startUploadAppStatistics onMySuccess statusCode : " + statusCode);
				if(jsonobject == null){
					MyLog.e(TAG, "startUploadAppStatistics onMySuccess jsonobject == null");
					return;
				}
				MyLog.d(TAG, "startUploadAppStatistics onMySuccess jsonobject : " + jsonobject.toString());
				if(statusCode == Constant.HTTP_200){
					MyLog.d(TAG, "startUploadAppStatistics onMySuccess upload success : ");
				}
			}
			
			@Override
			public void onMyFailure(int statusCode, Header[] headers,
					Throwable throwable, JSONObject errorResponse) {
				super.onMyFailure(statusCode, headers, throwable, errorResponse);
				if(dialogStatic != null)dialogStatic.dismiss();
				isCommonErr(statusCode, errorResponse,context,url);
			}
		});
		  
	}
	/**
	 * 忘记密码
	 * @param context
	 * @param email
	 */
	public static void startForgotPassword(final Context context,/*String loginName,*/String email){
		  if (!NetworkUtils.isNetworkAvailable(context)) {
	            MyToast.showMessage(context.getApplicationContext(), R.string.link_network_failure);
	            return;
	        }
		  
		  final ProgressDialog dialogStatic = new ProgressDialog(context);
		  	dialogStatic.setMessage(context.getString(R.string.msg_common_i_wait));
	        dialogStatic.setCancelable(false);
	        dialogStatic.show();
	        
		  ForgotPasswordDto forgotPasswordDto = new ForgotPasswordDto(/*loginName,*/ email);
		  String json = JSON.toJSONString(forgotPasswordDto);
		  final String url = ConstantURL.FORGET_PASSWORD;
		  RequestUtils.clientPost(context, url, new ByteArrayEntity(json.getBytes()), Constant.STR_APPLICATION_JSON, new NetCallBack(){
			  @Override
			public void onMySuccess(int statusCode, Header[] aheader,
					JSONObject jsonobject) {
				super.onMySuccess(statusCode, aheader, jsonobject);
				if(dialogStatic != null)dialogStatic.dismiss();
				MyLog.d(TAG, "startForgotPassword onMySuccess statusCode : " + statusCode);
				if(jsonobject == null){
					MyLog.e(TAG, "startForgotPassword onMySuccess jsonobject == null");
					return;
				}
				MyLog.d(TAG, "startForgotPassword onMySuccess jsonobject : " + jsonobject.toString());
				if(statusCode == Constant.HTTP_200){
					MyLog.d(TAG, "startForgotPassword modify password success!");
					MyToast.showMessage(context, context.getResources().getString(R.string.email_send_success));
				}
			}
			  
			  @Override
			public void onMyFailure(int statusCode, Header[] headers,
					Throwable throwable, JSONObject errorResponse) {
				super.onMyFailure(statusCode, headers, throwable, errorResponse);
				if(dialogStatic != null)dialogStatic.dismiss();
				isCommonErr(statusCode, errorResponse,context,url);
			}
			  
		  });
	}
	
	/**
	 * 重置密码
	 * @param context
	 */
	public static void startResetPwdReqApi(final Context context,ChangePasswordReqDto resetPwdReqDto) {
		  if (!NetworkUtils.isNetworkAvailable(context)) {
	        	MyToast.showMessage(context.getApplicationContext(), R.string.link_network_failure);
	            return;
	        } 
		  
		     final ProgressDialog dialogStatic = new ProgressDialog(context);
		     	dialogStatic.setMessage(context.getString(R.string.msg_common_i_wait));
		        dialogStatic.setCancelable(false);
		        dialogStatic.show();
		        
		  String json = JSON.toJSONString(resetPwdReqDto);
          // 根据业务需要，登录后的页面在发送网络请求时，都要传输header（key("x-auth-token"固定),value（来源为登录成功时服务器返回的，由登录机能负责保存在本地））
		  String token = MySharedPreferences.getString2(VRApplication.getAppContext(), MySharedPreferences.NAME_NOT_CLEAR,Constant.LOGIN_SUCCESS_TOKEN);
			MyLog.d(TAG, "token startResetPwdReqApi : " + token);
			RequestUtils.clientToken.addHeader(Constant.STR_X_AUTH_TOKEN,token);
			final String url = ConstantURL.CHANGE_PWD_URL;
          RequestUtils.clientTokenPost(context,url, new ByteArrayEntity(json.getBytes()), Constant.STR_APPLICATION_JSON, new NetCallBack() {

				@Override
				public void onMySuccess(int statusCode, Header[] aheader,
						JSONObject jsonobject) {
					super.onMySuccess(statusCode, aheader, jsonobject);
					if(dialogStatic != null){
						dialogStatic.dismiss();
					}
					// 重设密码成功
					MyToast.showMessage(context,
							R.string.reset_pwd_success);
					LoginResultDto loginResultDto = JSON.parseObject(
							jsonobject.toString(), LoginResultDto.class);
					
					MyLog.d(TAG, "startResetPwdReqApi jsonObject : " + jsonobject.toString());

					if (loginResultDto != null) {
						// 保存
						MySharedPreferences.save2(context,MySharedPreferences.NAME_NOT_CLEAR,Constant.LOGIN_SUCCESS_ID,
								loginResultDto.getId());
						MySharedPreferences.save2(context, MySharedPreferences.NAME_NOT_CLEAR, Constant.LOGIN_SUCCESS_LOCKED,
								loginResultDto.getLocked());
						MySharedPreferences.save2(context,MySharedPreferences.NAME_NOT_CLEAR,
								Constant.LOGIN_SUCCESS_TOKEN,
								loginResultDto.getToken());
						MySharedPreferences.save2(context,MySharedPreferences.NAME_NOT_CLEAR,
								Constant.LOGIN_SUCCESS_EXPIRES,
								loginResultDto.getExpires());

						MyLog.d(TAG + " 修改密码后Token : ",
								loginResultDto.getToken());
					}
					
					boolean isExist = AppManager.getInstance().isActivityExist(CoreSettingActivity.class);
					MyLog.d(TAG, "isExist : " + isExist);
					if(!isExist){
						MyPageJump.pageJump(context, CoreSettingActivity.class);
					}
					AppManager.getInstance().finishActivity(
							(Activity)context);
					MyLog.d(TAG, "changePwdReqApi onSuccess ");
				}

				@Override
				public void onMyFailure(int statusCode, Header[] headers,
						Throwable throwable, JSONObject errorResponse) {
					super.onMyFailure(statusCode, headers, throwable,
							errorResponse);
					if(dialogStatic != null){
						dialogStatic.dismiss();
					}
					isCommonErr(statusCode,errorResponse,context,url);
				}
			});
	}
	
	/**
	 * 重新发送邮箱验证
	 * @param mContext
	 * @param loginName
	 * @param password
	 */
    public static void startSendVerifyAgain(final Context mContext,final String loginName,final String password) {
        if (!NetworkUtils.isNetworkAvailable(mContext)) {
            MyToast.showMessage(mContext, R.string.link_network_failure);
            return;
        }
        
        final ProgressDialog dialogStatic = new ProgressDialog(mContext);
        dialogStatic.setMessage(mContext.getString(R.string.msg_common_i_wait));
        dialogStatic.setCancelable(false);
        dialogStatic.show();
        
        RegisterReqDto registerReqDto = new RegisterReqDto();
        registerReqDto.setLoginName(loginName);
        try {
        	char[] encrypte = AESSecurityUtil.encrypt(password, Constant.KEY_AES);
        	System.out.println(encrypte);
        	registerReqDto.setPassword(encrypte);
		} catch (Exception e) {
			e.printStackTrace();
		}
        registerReqDto.setEmail(loginName);
        String json = JSON.toJSONString(registerReqDto);
        final String url = ConstantURL.VERIFY_EMAIL_AGAIN;
            MyLog.d(TAG,"startSendVerifyAgain register json in : " + json);
            RequestUtils.clientPost(mContext, url, new ByteArrayEntity(json.getBytes()), Constant.STR_APPLICATION_JSON, new NetCallBack() {
				@Override
				public void onMySuccess(int statusCode, Header[] aheader,
						JSONObject jsonobject) {
					super.onMySuccess(statusCode, aheader, jsonobject);
					if(dialogStatic != null)dialogStatic.dismiss();
					MyLog.d(TAG, "startSendVerifyAgain onMySuccess statusCode : " + statusCode);
					if(jsonobject == null){
						MyLog.e(TAG, "startSendVerifyAgain onMySuccess jsonobject == null");
						return;
					}
					MyLog.d(TAG, "startSendVerifyAgain onMySuccess jsonobject : " + jsonobject);
					if(statusCode == Constant.HTTP_200){
						MyLog.d(TAG, "startSendVerifyAgain successed!");
						MyToast.showMessage(mContext, mContext.getResources().getString(R.string.email_send_success));
					}
				}
				@Override
				public void onMyFailure(int statusCode, Header[] headers,
						Throwable throwable, JSONObject errorResponse) {
					super.onMyFailure(statusCode, headers, throwable, errorResponse);
					if(dialogStatic != null)dialogStatic.dismiss();
					isCommonErr(statusCode, errorResponse, mContext,url);
				}
			});
    }
    
    /**
     * 反馈信息
     * @param context
     * @param feedbackIem
     * @param feedback_content
     */
    public static void startFeedback(final Context context, FeedbackItem feedbackIem,final EditText feedback_content){
    	   if (!NetworkUtils.isNetworkAvailable(context)) {
               MyToast.showMessage(context, R.string.link_network_failure);
               return;
           }
    	   
    	   final ProgressDialog dialogStatic = new ProgressDialog(context);
           dialogStatic.setMessage(context.getString(R.string.msg_common_i_wait));
           dialogStatic.setCancelable(false);
           dialogStatic.show();
    	   
    	   String json = JSON.toJSONString(feedbackIem);
           MyLog.d(TAG,"startFeedback json in : " + json);
           
           String token =  MySharedPreferences.getString2(context.getApplicationContext(),MySharedPreferences.NAME_NOT_CLEAR, Constant.LOGIN_SUCCESS_TOKEN);
           MyLog.d(TAG, "startFeedback token : " + token);
           RequestUtils.clientToken.addHeader(Constant.STR_X_AUTH_TOKEN,token);
           final String url = ConstantURL.FEEDBACK;
           RequestUtils.clientTokenPost(context, url, new ByteArrayEntity(json.getBytes()), Constant.STR_APPLICATION_JSON, new NetCallBack(){
        	   @Override
        	public void onMySuccess(int statusCode, Header[] aheader,
        			JSONObject jsonobject) {
        		super.onMySuccess(statusCode, aheader, jsonobject);
        		if(dialogStatic != null)dialogStatic.dismiss();
        		MyLog.d(TAG, "startFeedback onMySuccess statusCode : " + statusCode);
				if(jsonobject == null){
					MyLog.e(TAG, "startFeedback onMySuccess jsonobject == null");
					return;
				}
				MyLog.d(TAG, "startFeedback onMySuccess jsonobject : " + jsonobject);
				if(statusCode == Constant.HTTP_200){
					MyLog.d(TAG, "startFeedback success...");
					MyToast.showMessage(context, R.string.successfully);
					//成功后feedback_content清空
					feedback_content.setText(null);
					 AppManager.getInstance().finishActivity((Activity)context);
					 
					 
				}
        	}
        	   
        	   @Override
        	public void onMyFailure(int statusCode, Header[] headers,
        			Throwable throwable, JSONObject errorResponse) {
        		super.onMyFailure(statusCode, headers, throwable, errorResponse);
        		if(dialogStatic != null)dialogStatic.dismiss();
        		isCommonErr(statusCode, errorResponse, context,url);
        	}
           });
    }
    
    /**
     * 获取CPU型号
     * @param context
     * @param cpuName
     */
    public static void startCPUInfo(final Context context,final String cpuName,final CPUInfoListener cpuInfoListener){
    	
    	MyLog.d(TAG, "startCPUInfo...");
    	
    	  if (!NetworkUtils.isNetworkAvailable(context)) {
              MyToast.showMessage(context, R.string.link_network_failure);
              return;
          }
    	  
    	  String url = ConstantURL.CPUINFO_CONTROLLER + cpuName;
    	  MyLog.d(TAG, "startCPUInfo url : " + url);
    	  
    	  RequestUtils.clientGet(context,url,new NetCallBack(){
    		
    		  @Override
    		public void onMySuccess(int statusCode, Header[] aheader,
    				JSONObject jsonobject) {
    			super.onMySuccess(statusCode, aheader, jsonobject);
    			MyLog.d(TAG, "startCPUInfo onMySuccess statusCode : " + statusCode);
				if(jsonobject == null){
					MyLog.e(TAG, "startCPUInfo onMySuccess jsonobject == null");
					return;
				}
				MyLog.d(TAG, "startCPUInfo onMySuccess jsonobject : " + jsonobject);
				
				if(statusCode == Constant.HTTP_200){
					CpuInfo cpuInfo = JSON.parseObject(jsonobject.toString(), CpuInfo.class);
					MyLog.d(TAG, "startCPUInfo CpuInfo : " + cpuInfo);
					if(cpuInfo != null){
						CpuInfo.saveOrUpdate(cpuInfo);
						cpuInfoListener.onCPUInfoListener(cpuInfo);
					}
				}
    		}
    		  
    		  @Override
    		public void onMyFailure(int statusCode, Header[] headers,
    				Throwable throwable, JSONObject errorResponse) {
    			super.onMyFailure(statusCode, headers, throwable, errorResponse);
    			
    			MyLog.e(TAG, "onMyFailure statusCode : " + statusCode);
    	        if(statusCode == 0 || errorResponse == null){
    	        	MyLog.e(TAG, "onMyFailure errorJsonobject == null");
    	        	return ;
    	        }
    	        
    	        MyLog.e(TAG, "onMyFailure errorResponse : " + errorResponse.toString());
    	        ServerErrorMsg errorMsg = JSON.parseObject(errorResponse.toString(), ServerErrorMsg.class);
    	        String errorKey = errorMsg.getError();
    	        String errorValue = errorMsg.getMessage();
    	        
    	        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E301)){
    	        	CpuInfo cpuInfo = new CpuInfo();
    	        	cpuInfo.setCpucode(Constant.CPUINFO_CPUCODE_UNKNOW);
    	        	CpuInfo.saveOrUpdate(cpuInfo);
    	        	return;
    	        }
    		}
    	  });
    }
    
    /**
     * 上传游戏下载次数
     * @param gameId
     */
    public static void addDownloadRecord(int gameId){
  	 String url = ConstantURL.DOWNLOAD_RECORD;
  	 MyLog.d(TAG,"addDownloadRecord url : " + url);
  	 
  	  String json = "{gameId:" + gameId + "}";
      MyLog.d(TAG,"addDownloadRecord json in : " + json);
      
      String token =  MySharedPreferences.getString2(VRApplication.getAppContext(),MySharedPreferences.NAME_NOT_CLEAR, Constant.LOGIN_SUCCESS_TOKEN);
      MyLog.d(TAG, "addDownloadRecord token : " + token);
      RequestUtils.clientToken.addHeader(Constant.STR_X_AUTH_TOKEN,token);
      RequestUtils.clientToken.addHeader(Constant.DEVICE, String.valueOf(DeviceType.ANDROID.getValue()));
  	  
  	RequestUtils.clientTokenPost(VRApplication.getAppContext(), url, new ByteArrayEntity(json.getBytes()), Constant.STR_APPLICATION_JSON,new NetCallBack(){
  		
  		@Override
  		public void onMySuccess(int statusCode, Header[] aheader,
  				JSONObject jsonobject) {
  			super.onMySuccess(statusCode, aheader, jsonobject);
  			MyLog.d(TAG, "addDownloadRecord onMySuccess statusCode : " + statusCode);
			if(jsonobject == null){
				MyLog.e(TAG, "addDownloadRecord onMySuccess jsonobject == null");
				return;
			}
			MyLog.d(TAG, "addDownloadRecord onMySuccess jsonobject : " + jsonobject);
			if(statusCode == Constant.HTTP_200){
				MyLog.d(TAG, "addDownloadRecord successful");
				
				
			}
  			
  		}
  		
  		@Override
  		public void onMyFailure(int statusCode, Header[] headers,
  				Throwable throwable, JSONObject errorResponse) {
  			super.onMyFailure(statusCode, headers, throwable, errorResponse);
  			
  			MyLog.e(TAG, "addDownloadRecord onMyFailure statusCode : " + statusCode);
	        if(statusCode == 0 || errorResponse == null){
	        	MyLog.e(TAG, "onMyFailure errorJsonobject == null");
	        	return ;
	        }
	        
	        MyLog.e(TAG, "addDownloadRecord onMyFailure errorResponse : " + errorResponse.toString());
  			
  		}
  		
  	});
    	
    }
    
    /**
     * 获取Feedback列表
     * @param feedbackReqDto
     */
//    public static void getFeedbackList(FeedbackReqDto feedbackReqDto,final NetCallbackLisener netCallbackLisener){
//    	String url = ConstantURL.FEEDBACK_LIST;
//    	String token =  MySharedPreferences.getString2(VRApplication.getAppContext(),MySharedPreferences.NAME_NOT_CLEAR, Constant.LOGIN_SUCCESS_TOKEN);
//    	String json = JSON.toJSONString(feedbackReqDto);
//
//    	 RequestUtils.clientToken.addHeader(Constant.STR_X_AUTH_TOKEN,token);
//    	 
//    	 RequestUtils.clientTokenPost(VRApplication.getAppContext(), url, new ByteArrayEntity(json.getBytes()), Constant.STR_APPLICATION_JSON, new NetCallBack(){
//    		 
//    		 @Override
//    		public void onMySuccess(int statusCode, Header[] headers,
//    				JSONArray response) {
//    			super.onMySuccess(statusCode, headers, response);
//    			MyLog.d(TAG, "getFeedbackList onMySuccess statusCode : " + statusCode);
//    			if(response == null){
//    				MyLog.e(TAG, "getFeedbackList onMySuccess response == null");
//    				return;
//    			}
//    			MyLog.d(TAG, "getFeedbackList onMySuccess response : " + response);
//    			if(statusCode == Constant.HTTP_200){
//    				MyLog.d(TAG, "getFeedbackList successfully");
//    				List<FeedbackListRespDto> feedbackListRespDto = JSON.parseArray(response.toString(), FeedbackListRespDto.class);
//    				netCallbackLisener.onNetSuccess(feedbackListRespDto);
//    				
//    			}
//    			
//    		}
//    		 
//    		 @Override
//    		public void onMyFailure(int statusCode, Header[] headers,
//    				Throwable throwable, JSONObject errorResponse) {
//    			super.onMyFailure(statusCode, headers, throwable, errorResponse);
//      			MyLog.e(TAG, "getFeedbackList onMyFailure statusCode : " + statusCode);
//    	        if(statusCode == 0 || errorResponse == null){
//    	        	MyLog.e(TAG, "getFeedbackList errorJsonobject == null");
//    	        	return ;
//    	        }
//    	        MyLog.e(TAG, "getFeedbackList onMyFailure errorResponse : " + errorResponse.toString());
//    		}
//    		 
//    	 });
//    }
    
    /**
     * 获取Feedback请求次数
     */
//    public static void getFeedbackNoReadCount(final NetCallbackLisener netCallbackLisener){
//    	String url = ConstantURL.FEEDBACK_NOT_READ_COUNT;
//    	String token =  MySharedPreferences.getString2(VRApplication.getAppContext(),MySharedPreferences.NAME_NOT_CLEAR, Constant.LOGIN_SUCCESS_TOKEN);
//    	 RequestUtils.clientToken.addHeader(Constant.STR_X_AUTH_TOKEN,token);
//    	 RequestUtils.clientTokenPost(VRApplication.getAppContext(), url, new NetCallBack(){
//    		 
//    		 @Override
//    		public void onMySuccess(int statusCode, Header[] aheader,
//    				JSONObject jsonobject) {
//    			super.onMySuccess(statusCode, aheader, jsonobject);
//    			MyLog.d(TAG, "getFeedbackNoReadCount onMySuccess statusCode : " + statusCode);
//    			if(jsonobject == null){
//    				MyLog.e(TAG, "getFeedbackNoReadCount onMySuccess jsonobject == null");
//    				return;
//    			}
//    			MyLog.d(TAG, "getFeedbackNoReadCount onMySuccess jsonobject : " + jsonobject);
//    			if(statusCode == Constant.HTTP_200){
//    				FeedbackCountRespDto feedbackCountRespDto = JSON.parseObject(jsonobject.toString(),FeedbackCountRespDto.class);
//    				MyLog.d(TAG, "getFeedbackList successfully feedbackCountRespDto : " + feedbackCountRespDto.toString());
//    				netCallbackLisener.onNetSuccess(feedbackCountRespDto);
//    			}
//    		}
//    		 
//    		 @Override
//    		public void onMyFailure(int statusCode, Header[] headers,
//    				Throwable throwable, JSONObject errorResponse) {
//    			super.onMyFailure(statusCode, headers, throwable, errorResponse);
//      			MyLog.e(TAG, "getFeedbackNoReadCount onMyFailure statusCode : " + statusCode);
//    	        if(statusCode == 0 || errorResponse == null){
//    	        	MyLog.e(TAG, "getFeedbackNoReadCount errorJsonobject == null");
//    	        	return ;
//    	        }
//    	        MyLog.e(TAG, "getFeedbackNoReadCount onMyFailure errorResponse : " + errorResponse.toString());
//    		}
//    		 
//    	 });
//    }
    
    //===========================================================================================================
    /**
     * 
     * @param statusCode
     * @param mContext
     * @return
     * 服务器返回错误信息
     */
    public static boolean isCommonErr(int statusCode,JSONObject errorJsonobject,Context mContext,String url) {
    	MyLog.e(TAG, "error statusCode : " + statusCode);
    	MyLog.e(TAG, "error url : " + url);
        if (mContext == null) {
        	MyLog.e(TAG, "error mContext == null");
            return false;
        }
        if(statusCode == 0 || errorJsonobject == null){
        	MyLog.e(TAG, "error errorJsonobject == null");
        	MyToast.showMessage(mContext, R.string.network_error);
        	return false;
        }
        MyLog.e(TAG, "error errorJsonobject : " + errorJsonobject.toString());
        ServerErrorMsg errorMsg = JSON.parseObject(errorJsonobject.toString(), ServerErrorMsg.class);
        String errorKey = errorMsg.getError();
        String errorValue = errorMsg.getMessage();
        
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E101)){
        	if(url.equals(ConstantURL.VERIFY_EMAIL_AGAIN)){
        		MyToast.showMessage(mContext, R.string.send_email_again_error_tip);
        	}else{
        		MyToast.showMessage(mContext, R.string.msg_error_value_E101);
        	}
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E103)){
        	MyToast.showMessage(mContext, R.string.msg_error_value_E103);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E104)){
        	MyToast.showMessage(mContext, R.string.msg_error_value_E104);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E106)){
        	//MyToast.showMessage(mContext, R.string.msg_error_value_E106);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E108)){
        	//MyToast.showMessage(mContext, R.string.msg_error_value_E108);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E109)){
        	MyToast.showMessage(mContext, R.string.msg_error_value_E109);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E112)){
        	//MyToast.showMessage(mContext, R.string.msg_error_value_E112);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E113)){
        	MyToast.showMessage(mContext, R.string.msg_error_value_E113);
        	jumpLoginActivity(mContext);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E114)){
        	MyToast.showMessage(mContext, R.string.msg_error_value_E114);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E115)){
        	MyToast.showMessage(mContext, R.string.msg_error_value_E115);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E116)){
        	MyToast.showMessage(mContext, R.string.msg_error_value_E116);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E117)){
        	MyToast.showMessage(mContext, R.string.msg_error_value_E117);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E118)){
        	MyToast.showMessage(mContext, R.string.msg_error_value_E118);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E119)){
        	//提醒用户注册验证
        	MyToast.showMessage(mContext, mContext.getResources().getString(R.string.register_verify_not_verify_msg));
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E200)){
        	MyToast.showMessage(mContext, R.string.msg_error_value_E200);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E201)){
        	//MyToast.showMessage(mContext, R.string.msg_error_value_E201);
            jumpLoginActivity(mContext);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E202)){
        	//MyToast.showMessage(mContext, R.string.msg_error_value_E202);
        	 jumpLoginActivity(mContext);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E203)){
        	//MyToast.showMessage(mContext, R.string.msg_error_value_E203);
        	 jumpLoginActivity(mContext);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E301)){
        	//MyToast.showMessage(mContext, R.string.msg_error_value_E301);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E302)){
        	//MyToast.showMessage(mContext, R.string.msg_error_value_E302);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E303)){
        	//MyToast.showMessage(mContext, R.string.msg_error_value_E303);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E410)){
        	MyToast.showMessage(mContext, R.string.msg_error_value_E410);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E601)){
        	//MyToast.showMessage(mContext, R.string.msg_error_value_E601);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E602)){
        	//MyToast.showMessage(mContext, R.string.msg_error_value_E602);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E701)){
        	//	MyToast.showMessage(mContext, R.string.msg_error_value_E701);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E801)){
        	//MyToast.showMessage(mContext, R.string.msg_error_value_E801);
        	return true;
        }
        if(errorKey.equals(Constant.SERVER_ERROR_KEY_E999)){
        	String message = mContext.getString(R.string.ip_error_tip);
        	DialogUtils.showPromptDialog(mContext, "", message);
        	return true;
        }
        //如果没有服务器返回的信息则返回.
        MyToast.showMessage(mContext, R.string.network_error);
        return false;
    }

	private static void jumpLoginActivity(Context mContext) {
		MyLog.d(TAG, "jumpLoginActivity 111");
		String curClassName = null;
		if (mContext instanceof Activity) {
			MyLog.d(TAG, "jumpLoginActivity 222");
			Activity activity = (Activity) mContext;
			if(activity == null)return;
			curClassName = activity.getClass().getName();
			if (curClassName == null)
				return;
			MyLog.d(TAG, "jumpLoginActivity 333 curClassName : " + curClassName);
			if (!curClassName.equals(LoginActivity.class.getName())) {
				MyLog.d(TAG, "jumpLoginActivity 444");
				UserUtil.clearnData(mContext);
				Intent intent = new Intent();
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				intent.setClass(mContext, LoginActivity.class);
				mContext.startActivity(intent);
				AppManager.getInstance().finishAllActivity();
			}
		} else {
			Activity activity = AppManager.getInstance().currentActivity();
			if(activity == null)return;
			curClassName = activity.getClass().getName();
			if (curClassName == null)return;
			MyLog.d(TAG, "jumpLoginActivity 555 curClassName : " + curClassName);
			if(!curClassName.equals(LoginActivity.class.getName())){
				MyLog.d(TAG, "jumpLoginActivity 666");
				UserUtil.clearnData(mContext);
				Intent intent = new Intent();
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				intent.setClass(mContext, LoginActivity.class);
				mContext.startActivity(intent);
				AppManager.getInstance().finishAllActivity();
			}
		}
	}
}
